$(function(){
layui.use(['form','laypage','util','layer'],function(){
		
		var form = layui.form;
		form.render();
		var laypage=layui.laypage;
		var util=layui.util;
		var layer=layui.layer;
		var total;
		function find_sysUser_list(page,rows){ 
			$.ajax({
					type:"post",
					url:"http://localhost:8080/ssmService/sysUser/selectPageUserVo",
					async:false,
					data:{
							"queryParams.curr_page": page,
				    		"queryParams.page_size": rows
					},
						"beforSend":function(){
						index=layer.load(1,{
							shade:[0.5,"black"]
						});
					},
					"success":function(result){
						if(result.resultCode==0){
						build_sysUser_list(result);
						total=result.data.total;
						}else{
					 		layer.msg("服务器错误，请联系管理员",{
									icon:2,
									time:1000
							});
						} 
				} ,
				"error":function(){
					layer.msg("请求失败,联系管理员",{
								icon:2,
								time:2000
					});	
				}
		});			  
	}
				function build_sysUser_list(result){ 
					var userList=result.data.list; 
					console.log(userList)
					$(".table_tbody").empty();
					$.each(userList, function(index,item) {
						var tr=$("<tr></tr>");
						var td1=$("<td></td>").append("<input type='checkbox' user_id='"+item.user_id+"' lay-skin='primary'>");
						var td2=$("<td></td>").append(item.user.account);
						var td3=$("<td></td>").append(item.user.name);
						var phone="";
						if(item.user.phone!=null){
							phone=item.user.phone;
						}
						var td4=$("<td></td>").append(phone);
						var address=""; 
						if(item.user.address!=null){
							address=item.user.address;
						}
						var td5=$("<td></td>").append(address);
						var birthday="";
						if(item.user.birthday!=null){
							birthday=item.user.birthday;
						}
						var td6=$("<td></td>").append(util.toDateString(birthday,"yyyy-MM-dd"));
						var td7=$("<td></td>").append("<input type='checkbox' user_id='"+item.user_id+"' name='' lay-skin='switch' lay-text='ON|OFF'>");
						var td8 = $("<td></td>").append("<a href='#' user_id='"+item.user_id+"' class='layui-btn layui-btn-sm updateUser'>编辑</a>")
				    		.append("<a href='' user_id='"+item.user_id+"' class='layui-btn layui-btn-sm'>重置密码</a>")
				    		.append("<a href='' user_id='"+item.user_id+"' class='layui-btn layui-btn-sm layui-btn-danger'>删除</a>");
				    		tr.append(td1).append(td2).append(td3).append(td4).append(td5).append(td6).append(td7).append(td8).appendTo(".table_tbody");
					});
					form.render();
				} 
			find_sysUser_list(1,10); 
			laypage.render({
				elem:"table_page",
				count:total,
				layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'],
				jump:function(obj,first){
					find_sysUser_list(obj.curr,obj.limit);
					
				}
			});
		$(".addUser").click(function(){
			var index=layer.open({
				type:2,
				content:'insertuser.html',
				title:false,
				maxmin:true,
				closeBtn:1
		});
		layer.full(index);
			});
			
			$(".updateUser").click(function(){
			var index=layer.open({
				type:2,
				content:'EditorUser.html',
				title:false,
				maxmin:true,
				closeBtn:1
	});
			layer.full(index);
			});
		});
});